#include "loop_linklist.h"

LoopLinkList LoopLinkListNodeCreate()
{
    LoopLinkList list = (LoopLinkList)malloc(sizeof(LoopLinkListNode ));
    list->next = list;
    list->prior= list;
    list->data = -1;
    return list;
}

void LoopLinkListGenerateNode(LoopLinkList list)
{
    ElemType data = 100;
    if(LoopLinkListIsVoidNode(list)){
        LoopLinkList node1 = (LoopLinkList)malloc(sizeof(LoopLinkListNode ));
        node1->data = data++;

        /*在这个地方切记：用对象（个体）的眼光看待事物*/
        /*list的前驱和后驱都是node1*/
        list->next = node1;
        list->prior = node1;

        /*node1的前驱和后驱都是list*/
        node1->prior = list;
        node1->next = list;
    }
    while(data - 100 < 3){
        printf("isVoidNode\n");
        LoopLinkList node = (LoopLinkList)malloc(sizeof(LoopLinkListNode ));
        node->data = data;
        /*先设置后驱部分*/
        node->next = list->next;
        list->next->prior = node;

        /*再设置前驱部分*/
        node->prior = list;
        list->next = node;
        data++;
    }
}

void LoopLinkListTraverNode(LoopLinkList list)
{
    LoopLinkList head = list;
    printf("LoopLinkListTraverNode\n");
    while(head != list){
        head = head->next;
        printf("%d\n",head->next);
    }
}

int LoopLinkListIsVoidNode(LoopLinkList list)
{
    if(list->next == list->prior == list){
        return 1;
    }else{
        return -1;
    }

}
